package com.cee.admin.modules.industry;


import com.cee.common.utils.StringUtils;
import com.cee.common.web.result.Result;
import com.cee.domain.modules.industry.Industry;
import com.cee.ds.modules.industry.service.IIndustryService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.cee.admin.common.BaseController;

import java.util.List;

/**
 * <p>
 * 企业行业 前端控制器
 * </p>
 *
 * @author autoGenerator
 * @since 2023-12-22
 */
@RestController
@RequestMapping("/api/v1/industry")
@Tag(name = "行业")
public class IndustryController extends BaseController {

    @Autowired
    private IIndustryService industryService;

    @PostMapping("/get/{id}")
    @Operation(summary = "获取单个行业")
    public Result<Industry> get(@PathVariable("id") Integer id) {
        return success(industryService.getById(id));
    }

    @GetMapping("/list")
    @Operation(summary = "获取所有行业")
    public Result<List<Industry>> list(@Parameter(description = "模糊查找行业名") String likeName) {
        return success(StringUtils.isBlank(likeName) ? industryService.list() : industryService.lambdaQuery().like(Industry::getName, likeName).list());
    }

    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody Industry industry){
        return success(industryService.save(industry));
    }

    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody Industry industry){
        return success(industryService.updateById(industry));
    }
}

